import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    // count: 0,
    // list: uni.getStorageSync("goods") || [],
    list: uni.getStorageSync("details") || [],

  },
  getters: {
    allCount(state) {
      let allCount = 0;
      state.list.forEach((goods) => {
        if (goods.checked) {
          allCount += goods.count;
        }
      });
      return allCount;
    },
    allPrice: state => {
      let allPrice = 0;
      state.list.forEach((goods) => {
        if (goods.checked) {
          allPrice += goods.goods_price * goods.count;
        }
      });
      return allPrice;
    },
  },
  mutations: {
    // addCount(state, num) {
    //   console.log("拿到请求的账单le");
    //   state.count += num
    //   console.log("修改后的数据", state.count);
    // }
    // setList(state, list) {
    //   // 使用数据长久化
    //   state.list = list
    //   uni.setStorageSync("goods", list);
    // }
    getList(state, list) {
      state.list = list
      uni.setStorageSync("details", list);
    }
  }
});
export default store;